package top.csy8888.likework.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.csy8888.likework.dto.PostDTO;
import top.csy8888.likework.entity.Post;
import top.csy8888.likework.mapper.PostMapper;
import top.csy8888.likework.service.LikeService;
import top.csy8888.likework.service.PostService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CSY
 * @date 2025 - 10 - 12
 */
@Service
@RequiredArgsConstructor
public class PostServiceImpl implements PostService {
    private final PostMapper postMapper;

    private final LikeService likeService;
    @Override
    public List<PostDTO> listPost(Integer userId){
        List<PostDTO> postDTOS = new ArrayList<>();
        postMapper.listPost().forEach(post -> {
            PostDTO postDTO = new PostDTO();
            postDTO.setPost(post);
            Boolean likeStatus = likeService.isLike(userId, post.getPostId());
            postDTO.setLikeStatus(likeStatus);
            postDTOS.add(postDTO);
        });
        return postDTOS;
    }

}
